Subject: Re: Use of Varptr
From: "Andrew Church" <[email-masked]>
To: "amos-list" <[email-masked]>
Date: 27 Sep 93 21:34:00 EST

>  Last night I was stuffing around with passing Varptr's as parameters to
>procedures, trying to pass the address of an array of floating point numbers.
>The problem is that I couldn't just Poke(Varptr(ARRAY)+OFFSET) to get to
>ARRAY(OFFSET).  I noticed that each successive Varptr was 4 units apart, and
>this morning I realized why the values I Poked weren't what was stored.
>  So could someone tell me 

>* How to use Varptr, Poke and Peek to store (properly) and read from an array
>  of integers?

  Writing: Loke Varptr(ARRAY(0))+ELEMENT*4,_VALUE
  Reading: _VALUE=Leek(Varptr(ARRAY(0))+ELEMENT*4)

where ELEMENT is the element number you're using, just like ARRAY(ELEMENT).

  Of course, this is only useful if you've passed the array address, as in

_PROCEDURE[Varptr(ARRAY(0))]

since otherwise you can just use _VALUE=ARRAY(ELEMENT).

>* How to use Varptr, Poke and Peek to store (properly) and read from an array
>  of floats? (Ie, the set up of the float, such as the mantissa length...that
>  sort of garbage, and where they are stored wrt the array's adress).

  They're also stored as 4-byte values, so use the same scheme I described
above to access them.

  The format depends on whether you're using Creator or Pro.  Creator uses FFP:

  31                     876     0
  | - - - mantissa - - - |S| exp |

where m is the mantissa (with an assumed binary point after the first digit),
S is the sign bit and exp is the bias-64 exponent.  In other words,
    exp = exponent+64

  Pro, on the other hand, uses IEEE single-precision.  I'm not entirely sure
about the format for IEEE floats.  If you use Set Double Precision, that
switches Pro to 8-byte double-precision floats, which is something completely
different.

  --Andy Church